// pages/apply/apply.ts
let App = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    project_id:1,
    name:'',
    price:"",
    server_id:'',
    period_id:'',
    server_name:'',
    period_name:'12期',
    period_num:12,
    servers:[],
    peroid:[],
    select:false,
    servers_box:false,
    period_box:false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      project_id:options.id,
      name : options.name,
      price : options.price
    })
  },
  /**
   * 提交
   */
  submit_order:function(){
    let pam = {
      project_id:this.data.project_id,
      project_name:this.data.name,
      price:this.data.price,
      period:this.data.period_num,
      server_name:this.data.server_name,
      server_id:this.data.server_id
    }
    App.http('post','customer_app_order',pam,function(res){
      if(res.code==1){
        wx.showToast({
          title: '已提交',
          icon:'success'
        })
        App.jump('../myorder/myorder');
      }
    })
  },
  /**
   * 获取客服人员和期数
   */
  getSalesAndPeriod(){
    let that = this;
    App.http('post','get_sales_period',{},function(res){
      if(res.code==1){
        that.setData({
          servers:res.data.servicer_list,
          peroid:res.data.period_list
        })
      }
    })
  },
/**
 *  点击下拉框
 */
toSelectServers() {
  this.setData({
    select: true,
    servers_box: true
  })
},
toSelectPeriod() {
  this.setData({
    select: true,
    period_box: true
  })
},
toSelect() {
  this.setData({
    select: false,
    servers_box: false,
    period_box: false
  })
},
/**
 * 选中客服
 */
selectdservers(e){
  let id = e.currentTarget.dataset.id;
  let name = e.currentTarget.dataset.name;
  this.setData({
    server_id:id,
    select: false,
    servers_box: false,
    server_name:name
  })
},
/**
 * 选中期数
 */
selectdperiods(e){
  let id = e.currentTarget.dataset.id;
  let name = e.currentTarget.dataset.name;
  this.setData({
    period_id:id,
    select: false,
    period_box: false,
    period_name:name+'期',
    period_num:name,
  })
},
/**
* 已选下拉框
*/
mySelect(e) {
  console.log(e)
  var name = e.currentTarget.dataset.name
  this.setData({
    grade_name: name,
    select: false
  })
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getSalesAndPeriod()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})